<?php
 namespace Models\Model;
 use Zend\Db\ResultSet\ResultSet; 
 use Zend\Db\TableGateway\TableGateway; 
 use Zend\Db\Sql; 
 use Zend\Db\Sql\Where; 
 use Zend\Db\Sql\Select;
 use Zend\Paginator\Adapter\DbSelect;
 use Zend\Paginator\Paginator; 
 use Zend\Db\Sql\Predicate; 
 use Zend\Db\Sql\Expression;
 class NotificationsTable {    
	protected $tableGateway; 	
	protected $select;    
	 public function __construct(TableGateway $tableGateway)    
	 {        
		 $this->tableGateway = $tableGateway; 		
		 $this->select = new Select();   
	 } 	
	public function sendAdminNotification($order_id,$usersNotification,$user_type,$admin_id,$uadtype){ 	
		$type=""; 		
		$userType=""; 		
		$AdminId=""; 
		$uordertype="";		
		if($user_type==2){ 			
		 $userType="USER"; 			
			 if($usersNotification['autoRenewal']==0){ 		
				$type=$usersNotification['hid_value']; 
			 }else if($usersNotification['autoRenewal']==1){ 
				$type="RENEWAL ORDER"; 		
			 } 		
		}else if($user_type==1){ 		
			$userType="ADMIN"; 			
			if($usersNotification['auto_renewal']==0){ 	
				$type="Cancelled Auto Renewal"; 			
			}else{ 				
				$type="Enabled Auto Renewal"; 		
			} 		
		}
		else{ 		
			$userType="SHOP"; 	
		} 
		if($admin_id==""){ 
			$AdminId=0; 		
		}else{ 			
			$AdminId=$admin_id; 	
		} 		
		if($uadtype==1){
			$uordertype="admin";	
		}else if($uadtype==2){
			$uordertype="user";
		}else{
			$uordertype="shop";
		}
		$data = array( 			
		 'order_id' 	  	       => $order_id,
		 'user_id' 		           => $usersNotification['user_id'], 
		 'shop_id' 		           => "", 			
		 'admin_id' 			   => $AdminId, 			
		 'complaint_id'  	       => "",	 
		 'rating_id' 	           => "", 
		 'type'	  	     		   => $type, 
		 'notifiedby' 		       => $userType, 
		 'user_type' 		       => $uordertype, 
		 'user_type_id' 		   => $uadtype, 
		 'added_date' 		       => date('Y-m-d H:i:s'), 	
		 'updated_date' 		   => date('Y-m-d H:i:s'), 
		 'status' 		      	   => 1,   			 
		 'count_status' 		   => 0,   			 
		 );	
		 $insertresult=$this->tableGateway->insert($data);	 
		 return $this->tableGateway->lastInsertValue;		  
	}	 
 // Notification	
	public function getNotification($type) {	
		 $select = $this->tableGateway->getSql()->select();
		 $select->join('user', new Expression('user.user_id=notifications.user_id'),
		 array('user_name'),'left');	 		
		 $select->where('notifications.added_date="'.date('Y-m-d').'"'); 		
		 //$select->where('(notifications.notifiedby="USER" OR notifications.notifiedby="SHOP") '); 		
		 $select->where('notifications.user_type="admin"'); 		
		 $select->where('notifications.status = 1'); 		
		 $resultSet = $this->tableGateway->selectWith($select);	 		
		 return $resultSet;		 	
	} 
	public function getcountAdminNotification($type) {	
		 $select = $this->tableGateway->getSql()->select();
		 $select->join('user', new Expression('user.user_id=notifications.user_id'),
		 array('user_name'),'left');	 		
		 $select->where('notifications.added_date="'.date('Y-m-d').'"'); 				
		 $select->where('notifications.user_type="admin"'); 		
		 $select->where('notifications.status = 1'); 		
		 $select->where('notifications.count_status = 0'); 		
		 $resultSet = $this->tableGateway->selectWith($select);	 		
		 return $resultSet;		 	
	} 
	public function getAdminNotification($uId){	 		
		$select = $this->tableGateway->getSql()->select(); 		
		/*$select->join('user', new Expression('user.user_id=notifications.admin_id'),
		array('user_name'),'left');*/	 		
		$select->where('added_date="'.date('Y-m-d').'"'); 		
		$select->where('user_type="user" '); 		 		
		$select->where('user_id="'.$uId.'"'); 		 		
		$select->where('(status = 2 OR status = 1)'); 		
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		 	
	}
	public function getcountUserNotification($userId){	 		
		$select = $this->tableGateway->getSql()->select(); 		
		/*$select->join('user', new Expression('user.user_id=notifications.admin_id'),
		array('user_name'),'left');*/	 		
		$select->where('added_date="'.date('Y-m-d').'"'); 		
		$select->where('user_type="user" '); 		 		
		$select->where('user_id="'.$userId.'"'); 		 		
		$select->where('(status = 2 OR status = 1)'); 		
		$select->where('count_status = 0 '); 		
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		 	
	}
	public function getAllUserNotifications($user_id)
    {	
		$select = $this->tableGateway->getSql()->select();
		$select->join('user', new Expression('user.user_id=notifications.admin_id'),array('user_name'),'left');	
		$select->where('(notifications.status = 0 OR notifications.status = 2)');
		$select->where('notifications.user_id = "'.$user_id.'"');
		$select->where('notifications.user_type = "user"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		
	}
	public function getAllAdminNotifications($user_id)
    {	
		$select = $this->tableGateway->getSql()->select();
		$select->join('user', new Expression('user.user_id=notifications.admin_id'),array('user_name'),'left');	
		$select->where('notifications.user_type = "admin"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		
	}
	public function getAllShopNotifications($shop_id)
    {	
		$select = $this->tableGateway->getSql()->select();
		$select->join('user', new Expression('user.user_id=notifications.admin_id'),array('user_name'),'left');	
		$select->where('notifications.user_type = "shop"');
		$select->where('notifications.shop_id = "'.$shop_id.'"');
		$select->where('notifications.status != "1"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		
	}
	public function updateNotificationStatus($O_Id,$orderType){
		$order_type="";
		$UserType="";
		if($orderType['OrderType']==7){
			$order_type="Register";
		}else if($orderType['OrderType']==8){
			$order_type="ShopRegister";
		}
		$data = array(
			'status' 	  	       	   => 0, 				
			'updated_date'	  	       => date('Y-m-d H:i:s'), 	
		);
		$updatenfcstatus=$this->tableGateway->update($data, array('type' => $order_type, 'user_id'=>$O_Id ,'user_type_id'=>$orderType['userType']));
		return $updatenfcstatus;	
    }
	public function updatecomreview($n_id,$orderType){
		$order_type="";
		$UserType="";
		if($orderType['OrderType']==5){
			$order_type="Complaint";
		}else if($orderType['OrderType']==6){
			$order_type="ReviewRating";
		}else if($orderType['OrderType']==11){
			$order_type="sendPrice";
		}else if($orderType['OrderType']==16){
			$order_type="OrderConfirmed";
		}else if($orderType['OrderType']==13){
			$order_type="Discount";
		}else if($orderType['OrderType']==12){
			$order_type="Confirmed";
		}else if($orderType['OrderType']==15){
			$order_type="OrderConfirmed";
		}
		$data = array(
			'status' 	  	       	   => 0, 				
			'updated_date'	  	       => date('Y-m-d H:i:s'), 	
		);
		$updatenfcstatus=$this->tableGateway->update($data, array('type' => $order_type, 'notifications_id'=>$n_id ,'user_type_id'=>$orderType['userType']));
		return $updatenfcstatus;	
    }
	public function updateCountStatus($countStatus){
		foreach($countStatus as $cStatus){
			$data = array(
			'count_status' 	  	       	   => 1, 				
			'updated_date'	  	      	   => date('Y-m-d H:i:s'), 	
			);
			$updatenfcstatus=$this->tableGateway->update($data, array('notifications_id' => $cStatus['notifications_id']));
		}
		return $updatenfcstatus;	
    }
	public function updateConforderNotStatus($sId,$orderType){
		$order_type="";
		$UserType="";
		if($orderType['OrderType']==10){
			$order_type="sendQuotation";
		}
		$data = array(
			'status' 	  	       	   => 0, 				
			'updated_date'	  	       => date('Y-m-d H:i:s'), 	
		);
		$updatenfcstatus=$this->tableGateway->update($data, array('type' => $order_type, 'shop_id'=>$sId ,'user_type_id'=>$orderType['userType']));
		return $updatenfcstatus;	
    }
	public function changeNotificationStatus($Oid,$orderType){
		$order_type="";
		$UserType="";
		if($orderType['OrderType']==0){
			$order_type="Enabled Auto Renewal";
		}else if($orderType['OrderType']==1){
			$order_type="Cancelled Auto Renewal";
		}else if($orderType['OrderType']==2){
			$order_type="Complaint";
		}else if($orderType['OrderType']==3){
			$order_type="RENEWAL ORDER";
		}else if($orderType['OrderType']==4){
			$order_type="ORDER";
		}else if($orderType['OrderType']==5){
			$order_type="Complaint";
		}else if($orderType['OrderType']==6){
			$order_type="ReviewRating";
		}else if($orderType['OrderType']==9){
			$order_type="Cancelled";
		}
		$data = array(
			'status' 	  	       	   => 0, 				
			'updated_date'	  	       => date('Y-m-d H:i:s'), 	
		);
		$updateuserid=$this->tableGateway->update($data, array('type' => $order_type, 'order_id'=>$Oid ,'user_type_id'=>$orderType['userType']));
		return $updateuserid;	
	}
	public function sendAdminComplaint($complaint,$user_type,$admin_id,$shop_id,$rating_id,$UsrtypeId){
		$type="";
		$userType="";
		$AdminId="";
		$ShopId="";
		$UseName="";
		if($user_type==2){
			$userType="USER";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="ReviewRating"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Register"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Shopregister"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Cancelled"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="sendQuotation"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==1){
			$userType="ADMIN";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="ReviewRating"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Register"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Shopregister"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Cancelled"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="sendQuotation"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==3){
			$userType="SHOP";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="ReviewRating"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Register"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Shopregister"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Cancelled"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="sendQuotation"){
				$type=$complaint['compliantType'];
			}
		}
		if($admin_id==""){
			$AdminId=0;
		}else{
			$AdminId=$admin_id;
		}
		if($shop_id==""){
			$ShopId=0;
		}else{
			$ShopId=$shop_id;
		}
		if($UsrtypeId==1){
			$UseName="admin";
		}else if($UsrtypeId==2){
			$UseName="user";
		}else{
			$UseName="shop";
		}
		$data = array(
			'order_id' 	  	      	   => $complaint['tracking_id'],	
			'user_id' 		           => $complaint['user_id'],  		
			'shop_id' 		           => $ShopId,
			'admin_id' 		           => $AdminId,
			'complaint_id'  	       => $complaint['complaint_id'],	
			'rating_id' 	           => $rating_id,   
			'type'	  	     		   => $type, 		
			'notifiedby' 		       => $userType,
			'user_type'	  	     	   => $UseName,
			'user_type_id' 		  	   => $UsrtypeId, 
			'added_date' 		       => date('Y-m-d H:i:s'), 			
			'updated_date' 		       => date('Y-m-d H:i:s'), 			
			'status' 		      	   => 1, 
			'count_status' 		   	   => 0,
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
	}	
	public function sendShopComplaint($complaint,$user_type,$admin_id,$shop_id,$rating_id,$UsrtypeId){
		$type="";
		$userType="";
		$AdminId="";
		$ShopId="";
		$UName="";
		if($user_type==2){
			$userType="USER";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="ReviewRating"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Register"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Shopregister"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==1){
			$userType="ADMIN";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="ReviewRating"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Register"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Shopregister"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==3){
			$userType="SHOP";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="ReviewRating"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Register"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Shopregister"){
				$type=$complaint['compliantType'];
			}
		}
		if($admin_id==""){
			$AdminId=0;
		}else{
			$AdminId=$admin_id;
		}
		if($shop_id==""){
			$ShopId=0;
		}else{
			$ShopId=$shop_id;
		}
		if($UsrtypeId==1){
			$UName="admin";
		}else if($UsrtypeId==2){
			$UName="user";
		}else{
			$UName="shop";
		}
		$data = array(
			'order_id' 	  	      	   => $complaint['tracking_id'],	
			'user_id' 		           => $complaint['user_id'],  		
			'shop_id' 		           => $ShopId,
			'admin_id' 		           => $AdminId,
			'complaint_id'  	       => $complaint['complaint_id'],	
			'rating_id' 	           => $rating_id,   
			'type'	  	     		   => $type, 		
			'notifiedby' 		       => $userType,
			'user_type'	  	     	   => $UName,
			'user_type_id' 		  	   => $UsrtypeId,
			'added_date' 		       => date('Y-m-d H:i:s'), 			
			'updated_date' 		       => date('Y-m-d H:i:s'), 			
			'status' 		      	   => 1,
			'count_status' 		  	   => 0,
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
	}	
	//Shop 
	public function shopNotifications($sh_id){	
		$select = $this->tableGateway->getSql()->select();
		$select->join('order_delivery_details', new Expression('order_delivery_details.user_medicine_order_id=notifications.order_id'),
		 array('user_medicine_order_id'),'left');
			$select->where('notifications.user_type="shop"');
			$select->where('notifications.shop_id="'.$sh_id.'"');
			$select->where('notifications.added_date="'.date('Y-m-d').'"');
			//$select->where('order_delivery_details.shop_order_status="2"');
			//$select->where('status = 2 ');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		
	}
	//Complaint
	public function getComRev($orderId){	
		$select = $this->tableGateway->getSql()->select();
			$select->where('user_type="shop"');
			$select->where('order_id="'.$orderId.'"');
			$select->where('(type = "Complaint" OR type = "ReviewRating")');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		
	}
	public function updateComRev($shop_id){	
		$data = array(
			'shop_id' 	  	       	   => $shop_id, 				
			'updated_date'	  	       => date('Y-m-d H:i:s'), 	
		);
		$updatenfcstatus=$this->tableGateway->update($data, array('shop_id' => $shop_id));
		return $updatenfcstatus;
	}
	//User
	public function usernot($u_id){	
		$select = $this->tableGateway->getSql()->select();
		$select->where('user_type="user"');
		$select->where('user_id="'.$u_id.'"');
		$select->where('added_date="'.date('Y-m-d').'"');
		$select->where('status = 2');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;		
	}
	public function getshopNotification($s_id){	
		$select = $this->tableGateway->getSql()->select();
		$select->join('user', new Expression('user.user_id=notifications.user_id'),array('user_name'),'left');	
		$select->where('notifications.shop_id="'.$s_id.'"');
		$select->where('notifications.user_type="shop"');
		$select->where('added_date="'.date('Y-m-d').'"');
		$select->where('(notifications.status = 1 OR notifications.status = 2)');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
	public function getcountShopNotification($s_id){	
		$select = $this->tableGateway->getSql()->select();
		$select->join('user', new Expression('user.user_id=notifications.user_id'),array('user_name'),'left');	
		$select->where('notifications.shop_id="'.$s_id.'"');
		$select->where('notifications.user_type="shop"');
		$select->where('added_date="'.date('Y-m-d').'"');
		$select->where('(notifications.status = 1 OR notifications.status = 2)');
		$select->where('notifications.count_status=0');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
	public function getshopNotifications($s_id){	
		$select = $this->tableGateway->getSql()->select();
		$select->where('added_date="'.date('Y-m-d').'"');
		$select->where('notifications.shop_id="'.$s_id.'"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
	public function sendNotificationsToShops($order){	
		$shopIds=explode('***',$order['shop_ids']);
		foreach($shopIds as $shopId)
		{
			$result[]=$this->sendAdminComplaint($order,'1','0',$shopId,'0','3');
		}
		return $result;	
	}
	public function sendPriceToAdmin($price,$u_type,$UsrtypeId){
		$type="";
		$userType="";
		$AdminId="";
		$ShopId="";
		$UseName="";
		if($u_type==2){
			$userType="USER";
			if($price['complaintType']=="sendPrice"){
				$type=$price['complaintType'];
			}
		}else if($u_type==1){
			$userType="ADMIN";
			if($price['complaintType']=="sendPrice"){
				$type=$price['complaintType'];
			}
		}else if($u_type==3){
			$userType="SHOP";
			if($price['complaintType']=="sendPrice"){
				$type=$price['complaintType'];
			}
		}
		if($UsrtypeId==1){
			$UseName="admin";
		}else if($UsrtypeId==2){
			$UseName="user";
		}else{
			$UseName="shop";
		}
		$data = array(
			'order_id' 	  	      	   => $price['t_id'],	
			'user_id' 		           => $price['user_id'], 		
			'shop_id' 		           => $price['shop_id'],
			'admin_id' 		           => $price['admin_id'],
			'complaint_id'  	       => "",	
			'rating_id' 	           => "",   
			'type'	  	     		   => $type, 		
			'notifiedby' 		       => $userType,
			'user_type'	  	     	   => $UseName,
			'user_type_id' 		  	   => $UsrtypeId, 
			'added_date' 		       => date('Y-m-d H:i:s'), 			
			'updated_date' 		       => date('Y-m-d H:i:s'), 			
			'status' 		      	   => 1,
			'count_status' 		 	   => 0,	
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;	
	}
	//Update send confirmation
	public function sendshopConfirmationorder($con_odr,$odr,$u_type,$UsrtypeId){
		foreach($con_odr as $con_odrid){
			$type="";
			$userType="";
			$AdminId="";
			$ShopId="";
			$UseName="";
			if($u_type==2){
				$userType="USER";
				if($odr['complaintType']=="Confirmed"){
					$type=$odr['complaintType'];
				}
			}else if($u_type==1){
				$userType="ADMIN";
				if($odr['complaintType']=="Confirmed"){
					$type=$odr['complaintType'];
				}
			}else if($u_type==3){
				$userType="SHOP";
				if($odr['complaintType']=="Confirmed"){
					$type=$odr['complaintType'];
				}
			}
			if($UsrtypeId==1){
				$UseName="admin";
			}else if($UsrtypeId==2){
				$UseName="user";
			}else{
				$UseName="shop";
			}
			$data = array(
				'order_id' 	  	      	   => $con_odrid['user_medicine_order_id'],	
				'user_id' 		           => $con_odrid['user_id'], 		
				'shop_id' 		           => $con_odrid['shop_id'],
				'admin_id' 		           => $odr['admin_id'],
				'complaint_id'  	       => "",	
				'rating_id' 	           => "",   
				'type'	  	     		   => $type, 		
				'notifiedby' 		       => $userType,
				'user_type'	  	     	   => $UseName,
				'user_type_id' 		  	   => $UsrtypeId, 
				'added_date' 		       => date('Y-m-d H:i:s'), 			
				'updated_date' 		       => date('Y-m-d H:i:s'), 			
				'status' 		      	   => $con_odrid['shop_order_status'],'count_status' 		     => 0,   			
			);	
			
			$insertresult=$this->tableGateway->insert($data);	
		}
		return $this->tableGateway->lastInsertValue;
	}
	public function senduserConfirmationorder($con_odr,$odr,$u_type,$UsrtypeId){
		foreach($con_odr as $con_odrid){
			$type="";
			$userType="";
			$AdminId="";
			$ShopId="";
			$UseName="";
			if($u_type==2){
				$userType="USER";
				if($odr['complaintType']=="Confirmed"){
					$type=$odr['complaintType'];
				}
			}else if($u_type==1){
				$userType="ADMIN";
				if($odr['complaintType']=="Confirmed"){
					$type=$odr['complaintType'];
				}
			}else if($u_type==3){
				$userType="SHOP";
				if($odr['complaintType']=="Confirmed"){
					$type=$odr['complaintType'];
				}
			}
			if($UsrtypeId==1){
				$UseName="admin";
			}else if($UsrtypeId==2){
				$UseName="user";
			}else{
				$UseName="shop";
			}
			$data = array(
				'order_id' 	  	      	   => $con_odrid['user_medicine_order_id'],	
				'user_id' 		           => $con_odrid['user_id'], 		
				'shop_id' 		           => $con_odrid['shop_id'],
				'admin_id' 		           => $odr['admin_id'],
				'complaint_id'  	       => "",	
				'rating_id' 	           => "",   
				'type'	  	     		   => $type, 		
				'notifiedby' 		       => $userType,
				'user_type'	  	     	   => $UseName,
				'user_type_id' 		  	   => $UsrtypeId, 
				'added_date' 		       => date('Y-m-d H:i:s'), 			
				'updated_date' 		       => date('Y-m-d H:i:s'), 			
				'status' 		      	   => $con_odrid['shop_order_status'], 'count_status' 		  	  => 0,  			
			);	
			$insertresult=$this->tableGateway->insert($data);	
		}
		return $this->tableGateway->lastInsertValue;
	}
	public function sendReplyShopComplaint($complaint,$user_type,$admin_id,$shop_id,$rating_id,$UsrtypeId,$user_id){
		$type="";
		$userType="";
		$AdminId="";
		$ShopId="";
		$UName="";
		if($user_type==2){
			$userType="USER";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="OrderConfirmed"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==1){
			$userType="ADMIN";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="OrderConfirmed"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==3){
			$userType="SHOP";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="OrderConfirmed"){
				$type=$complaint['compliantType'];
			}
		}
		if($admin_id==""){
			$AdminId=0;
		}else{
			$AdminId=$admin_id;
		}
		if($shop_id==""){
			$ShopId=0;
		}else{
			$ShopId=$shop_id;
		}
		if($UsrtypeId==1){
			$UName="admin";
		}else if($UsrtypeId==2){
			$UName="user";
		}else{
			$UName="shop";
		}
		$data = array(
			'order_id' 	  	      	   => $complaint['tracking_id'],	
			'user_id' 		           => $user_id,  		
			'shop_id' 		           => $ShopId,
			'admin_id' 		           => $AdminId,
			'complaint_id'  	       => $complaint['complaint_id'],	
			'rating_id' 	           => $rating_id,   
			'type'	  	     		   => $type, 		
			'notifiedby' 		       => $userType,
			'user_type'	  	     	   => $UName,
			'user_type_id' 		  	   => $UsrtypeId,
			'added_date' 		       => date('Y-m-d H:i:s'), 			
			'updated_date' 		       => date('Y-m-d H:i:s'), 			
			'status' 		      	   => 1,
			'count_status' 		   	   => 0,
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
	}	
	public function sendRenewalOrderNot($order_id,$usersNotification,$user_type,$admin_id,$uadtype,$user_id){ 	
		$type=""; 		
		$userType=""; 		
		$AdminId=""; 
		$uordertype="";		
		if($user_type==2){ 			
		 $userType="USER"; 			
			 if($usersNotification['autoRenewal']==0){ 		
				$type=$usersNotification['hid_value']; 
			 }else if($usersNotification['autoRenewal']==1){ 
				$type="RENEWAL ORDER"; 		
			 } 		
		}else if($user_type==1){ 		
			$userType="ADMIN"; 			
			if($usersNotification['auto_renewal']==0){ 	
				$type="Cancelled Auto Renewal"; 			
			}else{ 				
				$type="Enabled Auto Renewal"; 		
			} 		
		}
		else{ 		
			$userType="SHOP"; 	
		} 
		if($admin_id==""){ 
			$AdminId=0; 		
		}else{ 			
			$AdminId=$admin_id; 	
		} 		
		if($uadtype==1){
			$uordertype="admin";	
		}else if($uadtype==2){
			$uordertype="user";
		}else{
			$uordertype="shop";
		}
		$data = array( 			
		 'order_id' 	  	       => $order_id,
		 'user_id' 		           => $user_id, 
		 'shop_id' 		           => "", 			
		 'admin_id' 			   => $AdminId, 			
		 'complaint_id'  	       => "",	 
		 'rating_id' 	           => "", 
		 'type'	  	     		   => $type, 
		 'notifiedby' 		       => $userType, 
		 'user_type' 		       => $uordertype, 
		 'user_type_id' 		   => $uadtype, 
		 'added_date' 		       => date('Y-m-d H:i:s'), 	
		 'updated_date' 		   => date('Y-m-d H:i:s'), 
		 'status' 		      	   => 1, 
		 'count_status' 		   => 0,
		 );	
		 $insertresult=$this->tableGateway->insert($data);	 
		 return $this->tableGateway->lastInsertValue;		  
	}	 
	public function CancelledRenewalOrderNot($order_id,$usersNotification,$user_type,$admin_id,$uadtype,$user_id){ 	
		$type=""; 		
		$userType=""; 		
		$AdminId=""; 
		$uordertype="";		
		if($user_type==2){ 			
		 $userType="USER"; 			
			 if($usersNotification['auto_renewal']==0){ 	
				$type="Cancelled Auto Renewal"; 			
			}else{ 				
				$type="Enabled Auto Renewal"; 		
			} 		
		}else if($user_type==1){ 		
			$userType="ADMIN"; 			
			if($usersNotification['auto_renewal']==0){ 	
				$type="Cancelled Auto Renewal"; 			
			}else{ 				
				$type="Enabled Auto Renewal"; 		
			} 		
		}
		else{ 		
			$userType="SHOP"; 	
		} 
		if($admin_id==""){ 
			$AdminId=0; 		
		}else{ 			
			$AdminId=$admin_id; 	
		} 		
		if($uadtype==1){
			$uordertype="admin";	
		}else if($uadtype==2){
			$uordertype="user";
		}else{
			$uordertype="shop";
		}
		$data = array( 			
		 'order_id' 	  	       => $order_id,
		 'user_id' 		           => $user_id, 
		 'shop_id' 		           => "", 			
		 'admin_id' 			   => $AdminId, 			
		 'complaint_id'  	       => "",	 
		 'rating_id' 	           => "", 
		 'type'	  	     		   => $type, 
		 'notifiedby' 		       => $userType, 
		 'user_type' 		       => $uordertype, 
		 'user_type_id' 		   => $uadtype, 
		 'added_date' 		       => date('Y-m-d H:i:s'), 	
		 'updated_date' 		   => date('Y-m-d H:i:s'), 
		 'status' 		      	   => 1, 
		 'count_status' 		   => 0,
		 );	
		 $insertresult=$this->tableGateway->insert($data);	 
		 return $this->tableGateway->lastInsertValue;		  
	}	 	 
	public function sendcancelledComplaint($complaint,$user_type,$admin_id,$shop_id,$rating_id,$UsrtypeId,$user_id){
		$type="";
		$userType="";
		$AdminId="";
		$ShopId="";
		$UseName="";
		if($user_type==2){
			$userType="USER";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="OrderConfirmed"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Discount"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==1){
			$userType="ADMIN";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="OrderConfirmed"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Discount"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==3){
			$userType="SHOP";
			if($complaint['compliantType']=="Complaint"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="OrderConfirmed"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Discount"){
				$type=$complaint['compliantType'];
			}
		}
		if($admin_id==""){
			$AdminId=0;
		}else{
			$AdminId=$admin_id;
		}
		if($shop_id==""){
			$ShopId=0;
		}else{
			$ShopId=$shop_id;
		}
		if($UsrtypeId==1){
			$UseName="admin";
		}else if($UsrtypeId==2){
			$UseName="user";
		}else{
			$UseName="shop";
		}
		$data = array(
			'order_id' 	  	      	   => $complaint['tracking_id'],	
			'user_id' 		           => $user_id,  		
			'shop_id' 		           => $ShopId,
			'admin_id' 		           => $AdminId,
			'complaint_id'  	       => $complaint['complaint_id'],	
			'rating_id' 	           => $rating_id,   
			'type'	  	     		   => $type, 		
			'notifiedby' 		       => $userType,
			'user_type'	  	     	   => $UseName,
			'user_type_id' 		  	   => $UsrtypeId, 
			'added_date' 		       => date('Y-m-d H:i:s'), 			
			'updated_date' 		       => date('Y-m-d H:i:s'), 			
			'status' 		      	   => 1,  
			'count_status' 		  	   => 0,
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
	}
	public function sendshopActiveNotification($complaint,$user_type,$admin_id,$shop_id,$rating_id,$UsrtypeId,$user_id){
		$type="";
		$userType="";
		$AdminId="";
		$ShopId="";
		$UseName="";
		if($user_type==2){
			$userType="USER";
			if($complaint['compliantType']=="Active"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Block"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==1){
			$userType="ADMIN";
			if($complaint['compliantType']=="Active"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Block"){
				$type=$complaint['compliantType'];
			}
		}else if($user_type==3){
			$userType="SHOP";
			if($complaint['compliantType']=="Active"){
				$type=$complaint['compliantType'];
			}else if($complaint['compliantType']=="Block"){
				$type=$complaint['compliantType'];
			}
		}
		if($admin_id==""){
			$AdminId=0;
		}else{
			$AdminId=$admin_id;
		}
		if($shop_id==""){
			$ShopId=0;
		}else{
			$ShopId=$shop_id;
		}
		if($UsrtypeId==1){
			$UseName="admin";
		}else if($UsrtypeId==2){
			$UseName="user";
		}else{
			$UseName="shop";
		}
		$data = array(
			'order_id' 	  	      	   => $complaint['tracking_id'],	
			'user_id' 		           => $user_id,  		
			'shop_id' 		           => $ShopId,
			'admin_id' 		           => $AdminId,
			'complaint_id'  	       => $complaint['complaint_id'],	
			'rating_id' 	           => $rating_id,   
			'type'	  	     		   => $type, 		
			'notifiedby' 		       => $userType,
			'user_type'	  	     	   => $UseName,
			'user_type_id' 		  	   => $UsrtypeId, 
			'added_date' 		       => date('Y-m-d H:i:s'), 			
			'updated_date' 		       => date('Y-m-d H:i:s'), 			
			'status' 		      	   => 1, 
			'count_status' 		  	   => 0,
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
	}	
 }	